package cn.tedu.antconlonysever.contract.dao.persist.repository.impl;

import cn.tedu.antcolonycommons.pojo.vo.PageData;
import cn.tedu.antcolonycommons.util.PageInfoToPageDataConverter;
import cn.tedu.antconlonysever.contract.dao.persist.mapper.ContactMapper;
import cn.tedu.antconlonysever.contract.dao.persist.repository.IContactRepository;
import cn.tedu.antconlonysever.contract.pojo.entity.Contact;
import cn.tedu.antconlonysever.contract.pojo.entity.Loss;
import cn.tedu.antconlonysever.contract.pojo.vo.ContactListVO;
import cn.tedu.antconlonysever.contract.pojo.vo.ContactStandardVO;
import cn.tedu.antconlonysever.contract.pojo.vo.ContractListVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;
@Service
@Slf4j
public class ContactRepositoryImpl implements IContactRepository {
    @Autowired
    private ContactMapper contactMapper;
    @Override
    public int insert(Contact contact) {
        log.debug("开始执行【插入会面】的数据访问，参数：{}", contact);
        return contactMapper.insert(contact);
    }

    @Override
    public int insertBatch(List<Contact> contactList) {
        log.debug("开始执行【批量插入会面】的数据访问，参数：{}", contactList);
        return contactMapper.insertBatch(contactList);
    }

    @Override
    public int deleteById(Long id) {
        log.debug("开始执行【批量插入会面】的数据访问，参数：{}", id);
        return contactMapper.deleteById(id);
    }

    @Override
    public int deleteByIds(Collection<Long> idList) {
        return contactMapper.deleteBatchIds(idList);
    }

    @Override
    public int update(Contact contact) {
        return contactMapper.updateById(contact);
    }

    @Override
    public int count() {
        return contactMapper.selectCount(null);
    }

    @Override
    public int countCusId(Long cusId) {
        QueryWrapper<Contact> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("cus_id",cusId);
        return contactMapper.selectCount(queryWrapper);
    }

    @Override
    public int contactUsIdNotId(Long id, Long cusId) {
        QueryWrapper<Contact> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("cus_id",cusId)
                    .ne("id",id);
        return contactMapper.selectCount(queryWrapper);
    }

    @Override
    public ContactStandardVO getStandardById(Long id) {
        return contactMapper.getStandardById(id);
    }

    @Override
    public PageData<ContactListVO> list(Integer pageNum, Integer pageSize) {
        log.debug("开始执行【查询会面列表】的数据访问，页码：{}，每页记录数：{}", pageNum, pageSize);
        PageHelper.startPage(pageNum, pageSize);
        List<ContactListVO> list =contactMapper.list();
        PageInfo<ContactListVO> pageInfo = new PageInfo<>(list);
        PageData<ContactListVO> pageData = PageInfoToPageDataConverter.convert(pageInfo);
        return pageData;

    }
}
